package com.damionew.website.controller.back;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
 * @author yinyunqi
 * @datetime 2017/11/23
 * @Content 后台主页菜单管理
 */
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.damionew.website.model.back.Log;
import com.damionew.website.model.back.Member;
import com.damionew.website.model.back.Menu;
import com.damionew.website.model.back.User;
import com.damionew.website.service.back.LogService;
import com.damionew.website.service.back.MemberService;
import com.damionew.website.service.back.MenuService;
import com.damionew.website.service.back.UserService;
@Controller
@RequestMapping("/menu")
public class MenuController {
    @Autowired
    MenuService menuService;
    @Autowired
    MemberService memberService;
    //装配两个需要使用两个@Autowired
    @Autowired
    UserService userService;
    @Autowired
    LogService logService;
    //获取菜单列表并返回到菜单主页面左侧
    @RequestMapping("/index")
    public String getMenuList(Model model) {
    	logService.addLogRecord();
		//系统管理菜单
		List<Menu> systemList = menuService.getSystemMenu();
		System.out.println("123"+systemList.get(0).getUrl());
		//前台管理菜单
		List<Menu> frontList = menuService.getFrontMenu();
		model.addAttribute("systemList", systemList);
		model.addAttribute("frontList", frontList);
		Member member = (Member)SecurityUtils.getSubject().getPrincipal();
		String name = member.getName()+"("+member.getAccount()+")";
		String created_time = member.getCreated_at();
		model.addAttribute("name", name);
		model.addAttribute("created_time", created_time);
		return "back/index";
    }
    /**
     * 返回登录用户，角色描述等信息
     * @param model
     * @return 主页面
     */
    @RequestMapping("/main")
    public String menuMain(Model model,HttpServletRequest request) {
	int total = userService.getUserTotal();
	model.addAttribute("userTotal", total);
	
	return "back/menu/main";
    }
    
}
